
public class Testprimitive {
	public static void main(String[] args) {
		byte by  = 127;
		System.out.println( (by+1));
		by=  (byte) (by+1);
		System.out.println(by);
		
		
		
		int a1 = 12;
		long a2 = 23;
	int a3 = 	(int) (a1+a2);
		
		System.out.println("===========================");
		double d = 123;
		System.out.println(d);
		
		char c = 'A';
		
		System.out.println(c);
		
//		float f = 123F;
		
		int number =2;
		long longNumber = number;
		
		
		long longNumber1 = 2;
		number = (int) longNumber;
		
		/*
		 * 
		 * 	byte   8 bit   -128 to 127   -(2*(8))  to ((2*(8))-1)

	short  16 bit   -32,768 to 32767

	int    32-bit signed -2^31 and a maximum value of 231-1.

	long	64 bit signed 

	float   32 bit floting point

	double	64 bit floating point

	boolean true/false

	char     16 bit unicode charater  - a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 	65,535 inclusive).
	
		 */
		
		/*
		 * The widening conversion is permitted in the following cases:

		    byte to short, int, long, float, or double
		    Short to int, long, float, or double
		    char to int, long, float, or double
		    int to long, float, or double
		    long to float or double
		    float to double
		 */
		
		
		//   The narrowing primitive conversion must be explicit.
	    //   You need to specify the target type in parentheses.
		/*
			short to byte or char
		    char to byte or short
		    int to byte, short, or char
		    long to byte, short, or char
		    float to byte, short, char, int, or long
		    double to byte, short, char, int, long, or float
		 * 
		 */
		
		System.out.println("=========((((===");
		long a = 10;
	    int b = (int) a; // narrowing conversion
	    System.out.println(a);
	    System.out.println(b);
	    
	    
	    System.out.println("=============");
	    
	    
	    long e = 9876543210L;
	    int f = (int) e;
	    System.out.println(f);
	    
	    
	    /*
	     * An automatic type conversion will take place if the following two conditions are met:

    		The two types are compatible.
    		The destination type is larger than the source type.
	     */
	    
	    //Casting incompatible types
	    byte x;
	    int i = 257;
	    double y = 323.142;
	   
	    System.out.println("\nConversion of int to byte.");
	    x = (byte) i;
	    System.out.println("i and b " + i + " " + x);
	   
	    System.out.println("\nConversion of double to int.");
	    i = (int) y;
	    System.out.println("d and i " + y + " " + i);
	   
	    System.out.println("\nConversion of double to byte.");
	    x = (byte) y;
	    System.out.println("d and b " + y + " " + x);
	    
	}
}
